#include "StdAfx.h"
#include "IWord.h"




IWord::IWord(const PDULONGLONG ullID,
			 const PDWCHAR* pwc_meaning_chinese,
			 const PDWCHAR* pwc_meaning_foreign)
{
	this->_ullID = ullID;
	this->_pwc_meaning_chinese = _wcsdup(pwc_meaning_chinese);
	this->_pwc_meaning_foreign = _wcsdup(pwc_meaning_foreign);
	_pwc_pronounce = NULL;

	for ( PDUSHORT usIndex = 0; usIndex<MAX_EXAMPLE_NUM; usIndex++ )
	{
		memset(_pwc_example[usIndex],0,MAX_STRING_LENGTH);
	}

}

IWord::~IWord(void)
{
	reset();
}

void IWord::setPronounce(const PDWCHAR* pwc_pronounce)
{
	this->_pwc_pronounce = _wcsdup(pwc_pronounce);
}

PDBOOL IWord::setExample(const PDWCHAR* pwc_example, const PDUSHORT usIndex)
{
	if ( MAX_EXAMPLE_NUM < usIndex )
	{
		lstrcpyn(_pwc_example[usIndex],pwc_example,MAX_STRING_LENGTH);
		return true;
	}
	return false;
}

void IWord::reset(void)
{
	if ( NULL != _pwc_meaning_chinese)
	{
		delete []_pwc_meaning_chinese;
		_pwc_meaning_chinese = NULL;
	}

	if ( NULL != _pwc_meaning_foreign)
	{
		delete []_pwc_meaning_foreign;
		_pwc_meaning_foreign = NULL;
	}

	if ( NULL != _pwc_pronounce)
	{
		delete []_pwc_pronounce;
		_pwc_pronounce = NULL;
	}

	for (PDUCHAR ucIndex = 0; ucIndex<MAX_EXAMPLE_NUM; ucIndex++)
	{
		memset(this->_pwc_example[ucIndex],0,MAX_STRING_LENGTH);
	}
}
